package com.levy.utils;


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.*;


public class StringUtils1 extends org.apache.commons.lang.StringUtils {

    public static final String TA_LEFT = "left";
    public static final String TA_RIGHT = "right";

    /**
     * 缓存配置文件
     */
    final static Map<String, Properties> propMap = new HashMap<String, Properties>();

    /***************************************************************************/

    public StringUtils1() {
    }


    /***************************************************************************/

    /**
     * 获取WEB-INF目录下面server.xml文件的路径
     *
     * @return
     */
    public static String getPath() {
        //file:/D:/JavaWeb/.metadata/.me_tcat/webapps/TestBeanUtils/WEB-INF/classes/
        String path = Thread.currentThread().getContextClassLoader().getResource("").toString();
        path = path.replace('/', '\\'); // 将/换成\
        path = path.replace("file:", ""); //去掉file:
        path = path.substring(1); //去掉第一个\,如 \D:\JavaWeb...
        //System.out.println(path);
        return path;
    }


    /***************************************************************************/

    public static boolean isStringInValid(String... args) {
        for (String str : args) {
            if (str == null || str.length() == 0) {
                return true;
            }
        }
        return false;
    }


    /***************************************************************************/

    public static String middleString(String value, char item, int len) {
        if (len <= value.length()) {
            return value;
        }
        StringBuffer stringBuffer = new StringBuffer(len);
        for (int i = 0; i < len; i++) {
            stringBuffer.append(item);
        }
        int index = (len - value.length()) / 2;
        stringBuffer.replace(index, index + value.length(), value);
        return stringBuffer.toString();
    }


    /***************************************************************************/


    /**
     * 获取uuid 并去掉“-”符号
     *
     * @return
     */
    public static String getUUID() {
        String s = UUID.randomUUID().toString();
        //去掉“-”符号
        return s.substring(0, 8) + s.substring(9, 13) + s.substring(14, 18) + s.substring(19, 23) + s.substring(24);
    }


    /***************************************************************************/

    /**
     * 获取configFile配置文件下的proKey对应值
     *
     * @param configFile
     * @param proKey
     * @return
     */
    public static String getProperty(String configFile, String proKey) {
        Properties prop = propMap.get(configFile);
        if (prop != null) {
            return prop.getProperty(proKey);
        }
        InputStream in = null;
        try {
            in = StringUtils1.class.getClassLoader().getResource(configFile).openStream();
            prop = new Properties();
            prop.load(in);
            propMap.put(configFile, prop);
            return prop.getProperty(proKey);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        } finally {
            if (null != in) {
                try {
                    in.close();
                } catch (IOException e) {
                }
            }
        }
    }


    /***************************************************************************/

    /**
     * 判断 字符串是否已存在于list  如不存在则将string加入list中
     *
     * @param resource
     * @param addStr
     * @return
     */
    public static List<String> addStringToList(List<String> resource, String addStr) {
        Boolean isHave = false;
        for (String res : resource) {
            if (res.equals(addStr)) {
                isHave = true;
            }
        }
        if (!isHave) {
            resource.add(addStr);
        }
        return resource;
    }

    /***************************************************************************/

    public static boolean isBlank(String str) {
        int strLen;
        if (str == null || (strLen = str.length()) == 0) {
            return true;
        }
        for (int i = 0; i < strLen; i++) {
            if ((Character.isWhitespace(str.charAt(i)) == false)) {
                return false;
            }
        }
        return true;
    }


    /***************************************************************************/


    public static boolean isNotBlank(String str) {
        return !isBlank(str);
    }


    /***************************************************************************/
    /**
     * 将字符串 使用 separator 分割 并且存为list
     *
     * @param str       字符串
     * @param separator 分隔符
     * @return
     */
    public static List<String> changeStringToList(String str, String separator) {
        String[] splitStrs = str.split(separator);
        List<String> list = new ArrayList<String>();
        if (splitStrs.length == 0) {
            return null;
        }
        for (String splitStr : splitStrs) {
            list.add(splitStr);
        }
        return list;
    }


    /***************************************************************************/

    /**
     * 将字符串list 以 separator分隔符转化为String
     *
     * @param resource  list
     * @param separator 分隔符
     * @return
     */
    public static String changeListToStr(List<String> resource, String separator) {
        StringBuilder builder = new StringBuilder();

        if (resource == null || resource.size() == 0) {
            return null;
        }

        for (String str : resource) {
            builder.append(str).append(separator);
        }
        builder.deleteCharAt(builder.length() - 1);
        return builder.toString();
    }


    /***************************************************************************/

    public static String changeString2Sql(String str) {
        StringBuilder builder = new StringBuilder();

        List<String> list = changeStringToList(str, ",");
        for (int i = 0; i < list.size(); i++) {
            builder.append("'").append(list.get(i)).append("',");
        }
        builder.deleteCharAt(builder.length() - 1);
        return builder.toString();
    }


    /***************************************************************************/

    public static String changeString2Sql(List<String> list) {
        StringBuilder builder = new StringBuilder();

        for (int i = 0; i < list.size(); i++) {
            builder.append("'").append(list.get(i)).append("',");
        }
        builder.deleteCharAt(builder.length() - 1);
        return builder.toString();
    }


    /***************************************************************************/

    /**
     * 判断集合是否为空
     *
     * @param list
     * @return
     */
    public static boolean isListEmpty(List<String> list) {
        if (list == null || list.size() == 0) {
            return true;
        }
        return false;
    }


    /***************************************************************************/
    /**
     * 将长整形数据转换成${len}长度的字符串,不够前面补0
     *
     * @param value
     * @param len
     * @return
     */
    public static String numberPadding0(long value, int len) {
        return String.format("%0" + len + "d", value);
    }


    /***************************************************************************/
    /**
     * 将json格式的字符串解析成Map对象 <li>
     * json格式：{"name":"admin","retries":"3fff","testname"
     * :"ddd","testretries":"fffffffff"}
     */
//	public static HashMap<String, Object> toHashMap(Object object) {
//		HashMap<String, Object> data = new HashMap<String, Object>();
//		// 将json字符串转换成jsonObject
//		JSONObject jsonObject = JSONObject.fromObject(object);
//		@SuppressWarnings("rawtypes")
//		Iterator it = jsonObject.keys();
//		// 遍历jsonObject数据，添加到Map对象
//		while (it.hasNext()) {
//			String key = String.valueOf(it.next());
//			Object value = jsonObject.get(key);
//			data.put(key, value);
//		}
//		return data;
//	}


    /***************************************************************************/
    /**
     * 字符串按指定长度构造字符串,不足填空格
     */
    public static String toStringAlign(String str, int len, String align) {
        String alignText = new String(str);
        if (alignText.length() < len) {
            int count = len - alignText.length();
            while (count > 0) {
                if (StringUtils1.equalsIgnoreCase(align, StringUtils1.TA_LEFT)) {
                    alignText = alignText + " ";
                } else {
                    alignText = " " + alignText;
                }
                count--;
            }
        }
        return alignText;

    }


    /***************************************************************************/

    /**
     * 整数按指定长度构造字符串,不足填空格
     *
     * @param iVal
     * @param len
     * @param align left,right
     * @return String
     */
    public static String toStringAlign(int iVal, int len, String align) {
        return StringUtils1.toStringAlign(String.valueOf(iVal), len, align);
    }


    /***************************************************************************/

    /**
     * 长整数按指定长度构造字符串,不足填空格
     *
     * @param lVal
     * @param len
     * @param align
     * @return
     */
    public static String toStringAlign(long lVal, int len, String align) {
        return StringUtils1.toStringAlign(String.valueOf(lVal), len, align);
    }


    /***************************************************************************/

    /**
     * 从字符串中删除掉指定字符
     *
     * @param str
     * @param ch
     * @return
     */
    public static String remove(String str, char ch) {
        String temp = "";
        int index = 0;
        while (index < str.length()) {
            if (str.charAt(index) != ch) {
                temp = temp + String.valueOf(str.charAt(index));
            }
            index++;
        }
        return temp;
    }

    /***************************************************************************/

    /**
     * 从字符串中删除掉指定字符串
     *
     * @param str
     * @param revStr
     * @return
     */
    public static String remove(String str, String revStr) {
        return StringUtils1.replace(str, revStr, "");
    }

    /***************************************************************************/
    /* 整数按指定长度构造字符串,以字符填空格
     *
     * @param str
     * @param len
     * @param align
     * @param full
     * @return
     */
    public static String fullStringAlgin(String str, int len, String align,
                                         char full) {
        String temp = str;
        if (temp.length() < len) {
            int nCount = len - temp.getBytes().length;
            String fullstr = String.valueOf(full);
            while (nCount > 0) {
                if (StringUtils1.equalsIgnoreCase(align, StringUtils1.TA_LEFT)) {
                    temp = temp + fullstr;
                } else {
                    temp = fullstr + temp;
                }
                nCount--;
            }
        }
        return temp;
    }

    /***************************************************************************/
    /*
     * @param str1
     * @param str2
     * @return
     */
    public static boolean containsIgnoreCase(String str1, String str2[]) {
        boolean aEnable = false;
        for (int index = 0; index < str2.length; index++) {
            aEnable |= StringUtils1.equalsIgnoreCase(str1, str2[index]) ? true
                    : false;
        }
        return aEnable;
    }

    /***************************************************************************/
    /*
     * @param str1
     * @param str2
     * @return
     */
    public static boolean contains(String str1, String str2[]) {
        boolean aEnable = false;
        for (int index = 0; index < str2.length; index++) {
            aEnable |= StringUtils1.equals(str1, str2[index]) ? true : false;
        }
        return aEnable;
    }

    /***************************************************************************/
    /* 判断字符串在尾部是否以指定字符串
     *
     * @param str1
     * @param str2
     * @return
     */
    public static boolean endsWith(String str1, String str2) {
        if (str1 == null || str2 == null) {
            return false;
        }
        if (str1.length() < str2.length()) {
            return false;
        }
        for (int index = 0; index < str2.length(); index++) {
            if (str1.charAt(str1.length() - index - 1) != str2.charAt(str2
                    .length()
                    - 1 - index)) {
                return false;
            }
        }
        return true;
    }

    /***************************************************************************/
    /* 判断字符串在尾部是否以指定字符串(忽虑字符大小写)
     *
     * @param str1
     * @param str2
     * @return
     */
    public static boolean endsIgnoreCaseWith(String str1, String str2) {
        if (str1 == null || str2 == null) {
            return false;
        }
        return str1.length() >= str2.length() && StringUtils1.endsWith(str1.toUpperCase(), str2.toUpperCase());
    }

    /***************************************************************************/
    /* 判断字符串在开头是否以指定字符串
     *
     * @param str1
     * @param str2
     * @return
     */
    public static boolean startWith(String str1, String str2) {
        if (str1 == null || str2 == null) {
            return false;
        }
        if (str1.length() < str2.length()) {
            return false;
        }
        for (int index = 0; index < str2.length(); index++) {
            if (str1.charAt(index) != str2.charAt(index)) {
                return false;
            }
        }
        return true;
    }

    /***************************************************************************/
    /* 判断字符串在开头是否以指定字符串(忽虑字符大小写)
     *
     * @param str1
     * @param str2
     * @return
     */
    public static boolean startIgnoreCaseWith(String str1, String str2) {
        if (str1 == null || str2 == null)
            return false;
        if (str1.length() < str2.length())
            return false;
        return StringUtils1.startWith(str1.toUpperCase(), str2.toUpperCase());
    }

    /***************************************************************************/
    /* 判断字符串中是否包含指定字符串(忽虑字符大小写)
     *
     * @param lpBuffer
     * @param containsbuff
     * @return
     */
    public static boolean containsIgnoreCase(String lpBuffer,
                                             String containsbuff) {
        boolean retCode = false;
        if (containsbuff == null || containsbuff.length() <= 0) {
            return true;
        }
        if (lpBuffer == null || lpBuffer.length() <= 0
                || lpBuffer.length() < containsbuff.length()) {
            return false;
        }
        int index = 0;
        String temp;
        while (index < lpBuffer.length()) {
            temp = StringUtils1.mid(lpBuffer, index, containsbuff.length());
            if (StringUtils1.equalsIgnoreCase(temp, containsbuff) == true) {
                return true;
            }
            index++;
        }
        return retCode;
    }

    /***************************************************************************/
    /*
     * @param lpBuffer
     * @param containsbuff
     * @return
     */
    public static boolean containsIgnoreBlank(String lpBuffer,
                                              String containsbuff) {
        lpBuffer = StringUtils1.remove(lpBuffer, ' ');
        containsbuff = StringUtils1.remove(containsbuff, ' ');
        return StringUtils1.contains(lpBuffer, containsbuff);
    }

    /***************************************************************************/
    /* 判断两个字符串大小
     *
     * @param str1
     * @param str2
     * @return
     */
    public static int compare(String str1, String str2) {
        return str1.compareTo(str2);
    }

    /***************************************************************************/
    /* 判断两个字符串大小(忽虑字符大小写)
     *
     * @param str1
     * @param str2
     * @return
     */
    public static int compareIgnoreCase(String str1, String str2) {
        return str1.compareToIgnoreCase(str2);
    }


    /***************************************************************************/
    /* 根据分隔符提取字符串(不忽律空字符)
     *
     * @param str
     * @param splitChar
     * @return
     */
    public static String[] splitNoIgnoreBlank(String str, String splitChar) {
        List elementLst = new ArrayList();
        int index = 0, index1 = -splitChar.length();
        while (index1 < str.length()) {
            index = index1 + splitChar.length();
            index1 = StringUtils1.indexOf(str, splitChar, index);
            if (index1 < 0) {
                index1 = str.length();
            }
            elementLst.add(StringUtils1.substring(str, index, index1));
        }
        return (String[]) elementLst.toArray(new String[]{});
    }

    /***************************************************************************/
    /*
     * @param aITaskExpr
     * @return
     */
    public static String[][] splitExpr(String aITaskExpr) {
        List aVector = new Vector();
        if (StringUtils1.isBlank(aITaskExpr) == false
                && StringUtils1.contains(aITaskExpr, "=")) {
            String aITaskExprL[] = StringUtils1.split(aITaskExpr, ";");
            for (int index = 0; index < aITaskExprL.length; index++) {
                String temp[] = StringUtils1.split(aITaskExprL[index], "=");
                if (temp != null && temp.length > 0) {
                    aVector.add(new String[]{temp[0],
                            temp.length > 1 ? temp[1] : ""});
                }
            }
        }
        return (String[][]) aVector.toArray(new String[][]{});
    }

    /***************************************************************************/
    /*
     * @param aRefeValue
     * @param aITaskExpr
     * @return
     */
    public static String splitExpr(String aRefeValue, String aITaskExpr) {
        String aValue = aITaskExpr;
        String aITaskExprL[][] = StringUtils1.splitExpr(aITaskExpr);
        if (aITaskExprL != null && aITaskExprL.length > 0) {
            aValue = null;
            for (int index = 0; index < aITaskExprL.length; index++) {
                if (StringUtils1.equals(aITaskExprL[index][0], aRefeValue)) {
                    aValue = aITaskExprL[index][1];
                    break;
                }
            }
        }
        return aValue;
    }

    /***************************************************************************/
    /*
     * @param aITaskExpr
     * @param aITaskPrefe
     */
    public static void splitExpr(String aITaskExpr, Map aITaskExprList) {
        String aITaskExprL[][] = StringUtils1.splitExpr(aITaskExpr);
        if (aITaskExprL != null && aITaskExprL.length > 0) {
            for (int index = 0; index < aITaskExprL.length; index++)
                aITaskExprList
                        .put(aITaskExprL[index][0], aITaskExprL[index][1]);
        }
    }

    /***************************************************************************/
    /* 用ch替换字符串中指定位置的字符
     *
     * @param str
     * @param pos
     * @param ch
     */
    public static String replace(String str, int pos, char ch) throws Exception {
        if (str == null || str.getBytes().length <= pos) {
            throw new ArrayIndexOutOfBoundsException();
        }
        byte srcByte[] = str.getBytes();
        srcByte[pos] = (byte) ch;
        return new String(srcByte);
    }

    /***************************************************************************/
    /* 加密
     *
     * @param str
     * @return
     */
    public static String DoEncrypt(String str) {
        int i;
        int tmpch;
        StringBuffer enStrBuff = new StringBuffer();
        for (i = 0; i < str.length(); i++) {
            tmpch = (int) str.charAt(i);
            tmpch = tmpch ^ 0x01;
            tmpch = tmpch ^ 0x0a;
            enStrBuff.append(Integer.toHexString(tmpch));
        }
        return enStrBuff.toString().toUpperCase();
    }

    /***************************************************************************/
    /* 解密
     *
     * @param str
     * @return
     */
    public static String DoDecrypt(String str) {
        int tmpch;
        String deStr = str.toLowerCase();
        StringBuffer deStrBuff = new StringBuffer();
        for (int i = 0; i < deStr.length(); i += 2) {
            String subStr = deStr.substring(i, i + 2);
            tmpch = Integer.parseInt(subStr, 16);
            tmpch = tmpch ^ 0x01;
            tmpch = tmpch ^ 0x0a;
            deStrBuff.append((char) tmpch);
        }
        return deStrBuff.toString();
    }

    /**
     * 判断是否相同
     *
     * @param str1
     * @param str2
     * @return 是否相同
     */
    public static final boolean isSame(String str1, String str2) {
        if (StringUtils1.isBlank(str1) && StringUtils1.isBlank(str2)) {
            return true;
        } else if (!StringUtils1.isBlank(str1) && !StringUtils1.isBlank(str2)
                && str1.equals(str2)) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 判断字符串是否为空或空字符
     *
     * @param str
     * @return 是否为空
     */
    public static final boolean isNull(String str) {
        if (str == null || str.trim().equals("")) {
            return true;
        } else {
            return false;
        }
    }

    public static final boolean isRegxNumeric(String str) {
        if (str == null || str.trim().equals("")) {
            return false;
        } else {
            return str.matches("-?\\d+(\\.\\d+)?");
        }
    }

    /***************************************************************************/
    /* 根据加密算法计算密文
     *
     * @param algorithm
     *            消息摘要MD5和SHA-1
     * @param aEncryptString
     * @return
     */
    public static final byte[] DoEncrypt(String algorithm, String aEncryptString)
            throws Exception {
        MessageDigest messageDigest = null;
        try {
            messageDigest = MessageDigest.getInstance(algorithm);
            messageDigest.update(aEncryptString.getBytes());
            return messageDigest.digest();
        } catch (NoSuchAlgorithmException e) {
//			log.error("根据加密算法计算密文错误", e);
            throw new Exception("根据加密算法计算密文错误", e);
        } finally {
            if (messageDigest != null) {
                messageDigest.reset();
                messageDigest = null;
            }
        }
    }

    /***************************************************************************/
    /*
     * @param aVariableValue
     * @return
     */
    public static final String DoEnginVariable(String aVariableValue) {
        if (aVariableValue == null) {
            return null;
        }
        return "$" + aVariableValue;
    }

    /***************************************************************************/
    /* 字符串通配符算法 1,通配符*号，表示可以匹配任意多个字符 2,通配符问号?表示匹配一个字符
     * 举例:字符串test.txt,通配符为t?s*.txt为true
     *
     * @param pattern
     * @param str
     * @return
     */
    public static final boolean wildcardMatch(String str, String pattern) {
        int patternLength = pattern.length();
        int strLength = str.length();
        int strIndex = 0;
        char ch;
        for (int patternIndex = 0; patternIndex < patternLength; patternIndex++) {
            ch = pattern.charAt(patternIndex);
            if (ch == '*') {
                while (strIndex < strLength) {
                    if (wildcardMatch(str.substring(strIndex), pattern
                            .substring(patternIndex + 1))) {
                        return true;
                    }
                    strIndex++;
                }
            } else if (ch == '?') {
                strIndex++;
                if (strIndex > strLength) {
                    return false;
                }
            } else {
                if ((strIndex >= strLength || (ch != str.charAt(strIndex)))) {
                    return false;
                }
                strIndex++;
            }
        }
        return (strIndex == strLength);
    }

    /***************************************************************************/
    /*
     * @param aPackage
     * @return
     */
    public static final String wildcardRight(String aPackage, String aMatch) {
        String[] aWildCard = StringUtils1.split(aPackage, aMatch);
        return aWildCard[aWildCard.length - 1];
    }

    /***************************************************************************/
    /*
     * @param aPackage
     * @return
     */
    public static final String wildcardLeft(String aPackage, String aMatch) {
        StringBuffer aWildCard = new StringBuffer();
        String[] aWildMatch = StringUtils1.split(aPackage, aMatch);
        for (int index = 0; index < aWildMatch.length - 1; index++) {
            aWildCard.append(aWildMatch[index]);
            if (index < aWildMatch.length - 2) {
                aWildCard.append(aMatch);
            }
        }
        return aWildCard.toString();
    }

    /***************************************************************************/
    /*
     * @param aPlatformbin
     *            字符串字节
     * @return
     */
    public static final StringBuffer concatBinary(byte[][] aBinary) {
        StringBuffer aStringbin = new StringBuffer();
        for (int index = 0; index < aBinary.length; index++) {
            aStringbin.append(new String(aBinary[index])).append(
                    index != aBinary.length - 1 ? "\n" : "");
        }
        return aStringbin;
    }

    /***************************************************************************/
    /* 右切位
     *
     * @param len
     * @return
     */
    public static final String trimRight(String str, int len) {
        if (str == null || str.length() < len || len < 0) {
            return str;
        }
        return StringUtils1.substring(str, str.length() - len);
    }

    /***************************************************************************/
    /*
     * @param str
     * @param len
     * @return
     */
    public static final String trimLeft(String str, int len) {
        if (str == null || str.length() < len || len < 0) {
            return str;
        }
        return StringUtils1.substring(str, 0, len);
    }

    /***************************************************************************/
    /*
     * @param t
     * @return
     */
    public static final String doThrowable(Throwable t, int aVM_MAX_BYTE) {
        String aThrowable = null;
        try {
            Throwable tt = t;
            if (tt.getCause() != null) {
                tt = tt.getCause();
            }
            StringWriter aWrite = new StringWriter();
            PrintWriter out = new PrintWriter(aWrite);
            tt.printStackTrace(out);
            out.flush();
            out.close();
            out = null;
            aThrowable = aWrite.toString();
            aWrite.close();
            aWrite = null;
            if (aThrowable.getBytes().length > aVM_MAX_BYTE) {
                aThrowable = StringUtils1.substring(aThrowable, 0, aVM_MAX_BYTE);
            }
        } catch (Throwable e) {
        }
        return aThrowable;
    }

    /***************************************************************************/

    public static String getEmptyIfNullObj(Object str) {
        return str == null ? "" : str.toString();
    }


    /***************************************************************************/
    // 2011-07-07
    public static String getCurMonth() {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMM");
        String month = formatter.format(new Date());
        return month;
    }


    /***************************************************************************/
    public static String getDate(long date) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        String month = formatter.format(date);
        return month;
    }


    /***************************************************************************/
    // 2011-07-07
    public static String getDiffMonth(String inMonth, int i) {
        int iYear = Integer.valueOf(inMonth.substring(0, 4));
        int iMonth = Integer.valueOf(inMonth.substring(4, 6));
        int iMonthTmp = iMonth + i;
        int m = iMonthTmp % 12; // 月
        int n = iMonthTmp / 12; // 年

        if (m <= 0) {
            n--;
            m += 12;
        }
        String sMonth = m < 10 ? "0" + m : String.valueOf(m);

        return (iYear + n) + "" + sMonth;
    }


    /***************************************************************************/
    // MD5 加密算法
    public static String MD5(String inStr) {
        MessageDigest md5 = null;

        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }

        char[] charArray = inStr.toCharArray();
        byte[] byteArray = new byte[charArray.length];

        for (int i = 0; i < charArray.length; i++) {
            byteArray[i] = (byte) charArray[i];
        }

        byte[] md5Bytes = md5.digest(byteArray);
        StringBuffer hexValue = new StringBuffer();

        for (int i = 0; i < md5Bytes.length; i++) {
            int val = ((int) md5Bytes[i]) & 0xff;
            if (val < 16) {
                hexValue.append("0");
            }
            hexValue.append(Integer.toHexString(val));
        }

        return hexValue.toString();
    }

    /***************************************************************************/
    /**
     * 当字符串为空时,返回defaultValue,否则返回原字符串
     *
     * @param str          原字符串
     * @param defaultValue 被替换的字符
     * @return String
     */

    public static String nvl(String str, String defaultValue) {

        if (str == null) {
            str = defaultValue;
        }
        return str;
    }


    /***************************************************************************/
    /**
     * 判断两个字符串是否相等
     *
     * @param str1 字符串1
     * @param str2 字符串2
     * @return boolean 是否相等
     */

    public static boolean equals(String str1, String str2) {

        if (str1 == null && str2 == null || str1 != null && str1.equals(str2)) {
            return true;
        } else {
            return false;
        }

    }

    /***************************************************************************/

    public static String[] getParamFromString(String aSourceString,
                                              String aStartStr, String aEndStr) {
        aSourceString = aSourceString + aEndStr;
        String strSource = aSourceString;
        ArrayList strKey = new ArrayList();
        int iStartIndex = strSource.indexOf(aStartStr);
        int iStartLength = aStartStr.length();
        int iEndLength = aEndStr.length();
        String strTemp = "";
        strTemp = strSource.substring(iStartIndex + iStartLength, strSource
                .length());
        int iEndIndex = strTemp.indexOf(aEndStr)
                + strSource.substring(0, iStartIndex + iStartLength).length();
        if (iEndIndex == iStartIndex) {
            strKey.add(strTemp);
        }
        while ((iStartIndex != -1) && (iEndIndex != -1)
                && (iStartIndex < iEndIndex)) {
            strTemp = strSource
                    .substring(iStartIndex + iStartLength, iEndIndex);
            strKey.add(strTemp);
            strSource = strSource.substring(iEndIndex + iEndLength, strSource
                    .length());
            iStartIndex = strSource.indexOf(aStartStr);
            strTemp = strSource.substring(iStartIndex + iStartLength, strSource
                    .length());
            iEndIndex = strTemp.indexOf(aEndStr)
                    + strSource.substring(0, iStartIndex + iStartLength)
                    .length();
        }
        return ((String[]) (String[]) strKey.toArray(new String[0]));
    }

    /***************************************************************************/
    /*
     * @param argv
     */
    public static void main(String argv[]) {
        String str[][] = StringUtils1.splitExpr("A=01;B=02;C=03");
        System.out.println(getPath());
//		for (int index = 0; index < str.length; index++)
//			log.debug(str[index][0] + "\t" + str[index][1]);
    }

    public final static String getEmptyIfNull(String input) {
        return input == null ? "" : input;
    }
}

	
